import { computed, onUnmounted, ref } from "vue";
import dayjs from "dayjs";

export function useCutDown() {

    let timeId = 0;

    const time = ref(0);

    const formatTime = computed(() => dayjs.unix(time.value).format('mm分ss秒'));

    const start = (currentTime) => {
        
        time.value = currentTime;
        timeId = setInterval(() => {
            time.value--;
            console.log('time',time.value);
            console.log('formateTime',formatTime.value);
        }, 1000);
    }


    onUnmounted(()=>{
        if (time.value === 0) {
            clearInterval(timeId);
        }
    })

    return {
        formatTime,
        start
    }
}